package main;

import java.util.Vector;

import gui.Shortcut;
import gui.ShortcutFactory;
import gui.ShortcutFrame;
import gui.XMLConfig;
import gui.ShortcutFactory.FactoryType;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

import backend.FileIO;
import backend.PathHandler;
import backend.WindowShortcutsLoader;
import backend.XMLCommunicator;

/**
 * This is the main class of the Shortcut Utility. It calls the XMLReader to
 * generate a list of shortcuts and passes them to the frame.
 * 
 * @author Itai Raccah
 * 
 */
public class SULauncher {
	public static void main(String[] args) {
		XMLCommunicator xml = new XMLCommunicator();
		WindowShortcutsLoader winLoader = new WindowShortcutsLoader();
		Vector<Shortcut> shortcuts = new Vector<Shortcut>();
		if (args.length > 0) {
			if (args[0].equals("-config")){
				winLoader.getShortcutFiles(shortcuts, ShortcutFactory.getFactory(FactoryType.FILE_EDITOR));
				shortcuts = xml.getShortcuts(shortcuts, ShortcutFactory.getFactory(FactoryType.EDITOR));
				JLabel label = new JLabel(FileIO.loadFile(PathHandler.GetLocalPath()+ PathHandler.LICENSE));
				XMLConfig config = XMLConfig.getXMLConfig(shortcuts);
				config.setVisible(true);
				JOptionPane.showMessageDialog(config, label, "License", JOptionPane.PLAIN_MESSAGE, null);

			}
		} else {
			
			winLoader.getShortcutFiles(shortcuts, ShortcutFactory.getFactory(FactoryType.PLAIN));
			shortcuts = xml.getShortcuts(shortcuts, ShortcutFactory.getFactory(FactoryType.PLAIN));
			ShortcutFrame frame = ShortcutFrame.getInstance(shortcuts);
			frame.setVisible(true);
		}
	}
}
